<template>
	<view>
		<Header title='网易云音乐' color='black' :showIcon='false'/>
		
		<view class="scrollContainer">
			<scroll-view scroll-y="true" >
				<view class="serch" @tap='handleToSearch'>
					<text class="iconfont">&#xe63a;</text>
					<input type="text" placeholder="搜什么搜自己唱" />
				</view>
				
				<view v-if="loading" >
					<view  v-for='(item,ind) in skeletonArr' :key='ind' style="padding-left: 30rpx;margin-bottom: 30rpx;">
						<u-skeleton
							:loading='loading'
							:animate='true'
							rows='3'
							rowsWidth='80%'
							rowsHeight='25'
							:title='false'
							:avatar='true'
							avatarSize='100'
							avatarShape='square'
						>
						</u-skeleton>
					</view>
				</view>
				
				<view class="index-list" v-for="item in topList" :key='item.id' @tap='handleToList(item.id)' v-else>
					<view class="index-list-item">
						<view class="index-list-item-img">
							<image :src="item.coverImgUrl" mode=""></image>
							<text>{{item.updateFrequency}}</text>
						</view>
						
						<view class="index-list-item-text">
							<view v-for="(item,ind) in item.tracks" :key='ind'>{{ind + 1}}.{{item.first}} - {{item.second}}</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import {baseUrl} from '../../common/config.js'
	export default {
		data() {
			return {
				title: 'Hello',
				topList:[],
				loading:true,
				skeletonArr:[0,0,0,0]
			}
		},
		components:{
		},
		onLoad() {
			this.getTopListDetil()
		},
		methods: {
			getTopListDetil(){
				const url = baseUrl + '/toplist/detail'
				uni.$u.http.get(url).then((res)=>{
					if(res.data.list.length) {
						res.data.list.length = 4
						this.topList = res.data.list
						// console.log(res.data.list,'===');
					}
				}).finally(()=>{
						setTimeout(()=>{
							this.loading=false
						},1500)
				})
			},
			handleToList(id){
				uni.navigateTo({
					url: '/pages/list/list?id='+id
				});
			},
			handleToSearch(){
				uni.navigateTo({
					url: '../search/search'
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.serch {
		display: flex;
		align-items: center;
		height: 70rpx;
		// margin: 70rpx 30rpx 30rpx 30rpx;
		margin: 0 30rpx 30rpx 30rpx;
		background: #f7f7f7;
		border-radius: 50rpx;
		
		text {
			font-size: 30rpx;
			margin-right: 26rpx;
			margin-left: 28rpx;
		}
		
		input {
			font-size: 28rpx;
			flex: 1;
		}
	}
	
	.index-list {
		margin:0 30rpx;
		
		&-item {
			display: flex;
			margin-bottom: 34rpx;
			
			&-img {
				width: 212rpx;
				height: 212rpx;
				position: relative;
				border-radius: 30rpx;
				overflow: hidden;
				margin-right: 22rpx;
				
				image {
					width: 100%;
					height: 100%;
				}
				text {
					position: absolute;
					left: 12rpx;
					bottom: 16rpx;
					color: white;
					font-size: 20rpx;
				}
			}
			
			&-text {
				font-size: 24rpx;
				line-height: 66rpx;
				width: 66%;
				
				
				
				view {
					white-space: nowrap;
					overflow: hidden;
					width: 100%;
					text-overflow: ellipsis;
				}
				
				
			}
		}
	}
</style>
